package com.app.micaihu.view.main.topic.adapter;

import android.content.Context;
import android.view.View;
import android.view.ViewGroup;
import android.widget.TextView;

import com.app.micaihu.R;
import com.app.micaihu.base.AppBaseAdapter;
import com.app.micaihu.bean.topic.TopicInfo;
import com.app.micaihu.custom.view.CustomImageView;
import com.app.utils.util.ViewSizeUtils;
import com.app.utils.util.image.LoadImageUtils;

import java.util.List;

/**
 * 推荐话题的头部适配器
 * Created by linkai on 2016/9/14.
 */
public class RecommendHeadAdapter extends AppBaseAdapter<TopicInfo> {
    public RecommendHeadAdapter(List<TopicInfo> list, Context context) {
        super(list, context);
    }

    @Override
    public View creatView(int position, View convertView, ViewGroup parent) {
        ViewHolder viewHolder;
        if(convertView == null){
            convertView = inflater.inflate(R.layout.item_topic_recommend_head,null);
            viewHolder = new ViewHolder();
//            viewHolder.img = (CustomImageView) convertView.findViewById(R.id.img);
//            viewHolder.title = (TextView) convertView.findViewById(android.R.id.text1);
            ViewSizeUtils.changeViewAuto1080(viewHolder.img, 300, 300);
            convertView.setTag(viewHolder);
        }else{
            viewHolder = (ViewHolder) convertView.getTag();
        }
        TopicInfo topicInfo = list.get(position);
        if(topicInfo == null){
            return convertView;
        }
        LoadImageUtils.getInstance().loadImage(viewHolder.img, topicInfo.getBanner());
        viewHolder.title.setText("#"+topicInfo.getTitle()+"#");
        return convertView;
    }

    private class ViewHolder {

        CustomImageView img;
        TextView title;
    }
}
